
//Simple Client

import java.io.*;
import java.net.*;
import java.util.Random;

public class SimpleClient03 {

    public static void main(String arg[]){
	OutputStream	writer = null;
	InputStream	reader = null;
	byte		buf [] = new byte[200];
	String		msg    = null;
	Socket		sk = null;
	int		msgCount = 0;
	Random		rdm = new Random();

	try {
	    sk = new Socket("sleipnir.cs.csubak.edu", 9903);
	    writer=  sk.getOutputStream() ;
	    reader = sk.getInputStream () ;

	    while ( true ) {

		msg = "message from from client " + ++ msgCount ;
	        writer.write( msg.getBytes());
	    	writer.flush();

		int k = reader.read(buf);
	 	System.out.printf("client: %s\n", new String(buf).trim() );

	    	Thread.sleep(1000 + rdm.nextInt(7000) );
	    }

	}
	catch(Exception e) { e.printStackTrace(); } 

    }

}
